package com.cn.trip.service;

import com.cn.trip.DbDao.GoodsDao;
import com.cn.trip.bean.Goods;
import com.cn.trip.bean.Page;

import java.util.List;

public class GoodsService {
	
	public Page<Goods> getPageGoods(int pageNum, int pageSize){
		GoodsDao dao=new GoodsDao();
		List<Goods> allGoods=dao.getGoodsList();
		int totalRecord=allGoods.size();
		Page<Goods> page=new Page<>(pageNum, pageSize, totalRecord);
		int startIndex=page.getStartIndex();
		page.setList(dao.getPageGoods(startIndex, pageSize));
		return page;
	}
	
	public boolean addGoods(String goods_name,float price,String imgsrc,int stock) {
		Goods g=new Goods(0, goods_name, price, imgsrc, stock);
		GoodsDao dao=new GoodsDao();
		int flag=dao.addGoods(g);
		if(flag>0)
			return true;
		return false;
	}
}
